//
//  ContactManager.m
//  04-集合(二)
//
//  Created by dllo on 16/7/7.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "ContactManager.h"

@implementation ContactManager

- (instancetype)initWithDictionary:(NSMutableDictionary *)dictionary
{
    self = [super init];
    if (self) {
        _contactDic = dictionary;
    }
    return self;
}

- (void)addContact:(Contact *)contact
{
    if (contact.name.length > 0 && contact.phoneNumber.length > 0) {
        // 通过联系人的分组名, 取到对应的分组数组
        NSMutableArray *contactArr = [_contactDic objectForKey:contact.groupName];
        if (contactArr == nil) {
            contactArr = [NSMutableArray array];
            [contactArr addObject:contact];
            [_contactDic setObject:contactArr forKey:contact.groupName];
        } else {
            [contactArr addObject:contact];
        }
        NSLog(@"添加成功");
    } else {
        NSLog(@"添加失败");
    }
}

- (void)removeContactsWithGroupName:(NSString *)name
{
    [_contactDic removeObjectForKey:name];
}

@end
